<template>
	<view style="padding: 30rpx;">
		<view>
			<u-search placeholder="请输车牌号" v-model="plate" @search="pageNum=1;initData()"
				@custom="pageNum=1;initData()"></u-search>
		</view>
		<view style="background-color: #fff;border-radius: 16rpx;margin-top: 20rpx;">
			<u-radio-group v-model="carId">
				<u-cell-item @click="tjiao(item)" value="空闲中" :value-style="{'color':'green'}" :title="item.plate"
					:label="item.vehicleType" v-for="(item,index) in carLit" :key="index"></u-cell-item>
			</u-radio-group>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				carId: 0,
				carLit: [],
				plate: '',
				pageSize: 10,
				pageNum: 1,
				model: {
					"vehicleInfoId": "", //车辆id
					"driverInfoId": "", //司机（驾驶员个人信息id）
					"carCode": "", //车牌号
					"transportationCompanyId": "", //运输公司id
					"teamId": "", //4G运输公司id
					"transportationCompanyName": "", //运输公司名称
					"onOffStatus": "", //上下车状态:0.上车 1.下车
					"carUsageStatus": "" //车辆使用状态：0空闲中 1.使用中2.维修中
				},
				car: {},
			}
		},
		
		onLoad() {
			this.initData()
		},
		methods: {
			initData() {
				this.$u.get("/driver/vehicleInfoPage", {
					'carUsageStatus': this.sysConstant.IDLE_CAR_USAGE_STATUS,
					'plate': this.plate,
					// 'pageNum': this.pageNum,
					// 'pageSize': this.pageSize
				}).then(res => {
					if (res.code === 200) {
						this.carLit = res.rows
					}
				})
			},

			tjiao(car) {
				uni.showModal({
					title: '提示',
					content: '确认选择"' + car.plate + '"的车辆',
					success: (res) => {
						if (res.confirm) {
							console.log('用户点击确定');
							this.model.vehicleInfoId = car.id //车辆id
							this.model.driverInfoId = getApp().globalData.userId //司机（驾驶员个人信息id）
							this.model.carCode = car.plate //车牌号
							this.model.transportationCompanyId = car.transportationCompanyId //运输公司id
							this.model.teamId = car.itemId //4G运输公司id
							this.model.transportationCompanyName = car.enterpriseName //运输公司名称
							this.model.onOffStatus = 0 //上下车状态:0.上车 1.下车
							this.model.carUsageStatus = 1 //车辆使用状态：0空闲中 1.使用中2.维修中
							uni.showLoading({
								
							})
							this.submit()
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},

			submit() {
				this.$u.post("/driver/upperCar", this.model).then(res => {
					if(res.code==200){
						uni.hideLoading()
						uni.$emit('upperCar',{'status':0})
						uni.navigateBack({
							delta:1
						})
					}
				})
			}

		}
	}
</script>

<style>

</style>